﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace VisualWebGuiApplication2
{
    public partial class report2 : System.Web.UI.Page
    {
        int tankid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (null != Request.QueryString["id"])
                {
                    tankid = Convert.ToInt32(Request.QueryString["id"].ToString());
                    renderrep(tankid);
                }
            }
        }

        public void renderrep(int tankid)
        {
            using (GazOnDevEntities db =new GazOnDevEntities())
            {
               
              
                var query1 = from i in db.Tank_Stocks
                             where i.Id == tankid
                             select i;
               Tank_Stocks dd = query1.FirstOrDefault();

                var query2 = from i in db.TankFixOperations
                             where i.tankID == tankid
                             select i;

                //  dd.FirstOrDefault().Datetime = Convert.ToDateTime(dd.FirstOrDefault().Datetime.Value.ToString("MM/dd/yyyy"));
                //dd.FirstOrDefault().Date_of_Fix = Convert.ToDateTime(dd.FirstOrDefault().Date_of_Fix.Value.ToString("MM/dd/yyyy"));
               
                   List<TankFixOperation> ds2 = query2.ToList<TankFixOperation>();
                
              
              //  int personSigned = Convert.ToInt32(query1.FirstOrDefault().PersonRecipetsignid);
                // int transportCompanyid = Convert.ToInt32(query1.FirstOrDefault().TransportCompanyID);
                 this.reportViewer1.LocalReport.DataSources.Clear();
                // this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dd));
                 this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", ds2));
              //     SignPerson personrecipet=   db.SignPersons.FirstOrDefault(x=>x.id == personSigned);
                //  TransportCompany companytrans=   db.TransportCompanies.FirstOrDefault(x=>x.id == transportCompanyid);
                // ReportDataSource rds = new ReportDataSource("DataSet1", dd);
               //  this.reportViewer1.LocalReport.DataSources = dd;

                

                 string tanktype =string.Empty;
                if(dd.type == "0")
                {
                tanktype ="קרקעי";
                }
                if (dd.type == "1")
                {
                    tanktype = "עילי";
                }
                if (dd.type == "2")
                {
                    tanktype = "עילי עובר לתת";
                    
 

                }
                if (dd.type == "3")
                {
                    tanktype = "שינויים";
                }
               
               
                 ReportParameter p1 = new ReportParameter("manufacture_name", dd.manufacture_name);
                 ReportParameter p2 = new ReportParameter("Datetime", dd.Datetime);
                 ReportParameter p3 = new ReportParameter("Tank_Size", dd.Tank_Size.ToString());
                 ReportParameter p4 = new ReportParameter("type", tanktype);
                ReportParameter p5 = new ReportParameter("FixNum", dd.TankFixNumber);
                ReportParameter p6 = new ReportParameter("Year_of_manufacture", dd.Year_of_manufacture.ToString());
                ReportParameter p7 = new ReportParameter("TankNumber", dd.TankNumber);
                ReportParameter p8 = new ReportParameter("OrderName", dd.GazCompanyName );
                ReportParameter p9 = new ReportParameter("DatetimeNow", DateTime.Now.ToString("MM/dd/yyyy"));
       
             
                reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3,p4,p5,p6,p7,p8 });
          
                this.reportViewer1.DataBind();
                reportViewer1.LocalReport.Refresh();
              //  this.reportViewer1.Reset();

           //     this.reportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
                 //ReportDataSource rds = new ReportDataSource("DataSet1",AllFamilies.GetAllProjects);
                 //this.reportViewer1.LocalReport.DataSources = AllFamilies.GetAllProjects;
                

                
            }

            /* DataSet Data = new DataSet();
               Data.ReadXml(this.Context.Server.MapPath(ReportPath + "data.xml"));*/

            //if (MSMODE.Checked)
            //{
            //    Report.Render(Reporting.ReportViewer.RenderType.MSReportViewer, ReportPath, ReportName, ReportName, new ReportDataSource("Sales", Data.Tables[0]));
            //    MessageBox.Show("MS ReportViewer 2010 VWG support is broken -> IFrame Bug, Scriptmanager");
            //}
            //else
            //{
            //  Report.Render(Reporting.ReportViewer.RenderType.PDFReportViewer, ReportPath, ReportName, ReportName, new ReportDataSource("Sales", Data.Tables[0]));
            //}

            // this.Report..LocalReport.DataSources.Clear();
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetMoslemFamily", ListFamilyMoslemproj));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetFoodBox", ListFoodBoxmproj));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetPerson", ListPerson));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetHomeFix", ListHomeFix));
            //this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetSchoolBags", ListSchoolBags));

            //this.reportViewer1.Reset();

            //this.reportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
            // ReportDataSource rds = new ReportDataSource("DataSet1",AllFamilies.GetAllProjects);
            // this.reportViewer1.LocalReport.DataSources = AllFamilies.GetAllProjects;

            //this.reportViewer1.DataBind(); 
            // reportmoslemFamilyProjectBindingSource.DataSource = AllFamilies.GetAllProjects; 
            // Below code demonstrate the Parameter passing method. Use only if you have parameters into the reports.


            //ReportParameter p1 = new ReportParameter("FullName", currentPerson.FirstName + " " + currentPerson.FatherName + " " + currentPerson.LastName);
            //ReportParameter p2 = new ReportParameter("PersonID", currentPerson.IDnum);

            //reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2 });
            //reportViewer1.Visible = true;

        }
    }
}